package com.itclass.auth.authentication.token.supprt;


import com.itclass.auth.authentication.token.AbstractAuthenticationToken;
import com.itclass.auth.authentication.token.AbstractJsonAuthenticationToken;
import com.itclass.auth.pojo.dto.UserDetailsDTO;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 简单的账号密码登录 适配器
 */

public class UsernamePasswordLoginAuthenticationToken extends AbstractJsonAuthenticationToken<UserDetailsDTO> {

    /**
     * 用户名
     */
    private Object principal;
    /**
     * 密码
     */
    private Object credentials;
    private List<GrantedAuthority> authorities;

    public UsernamePasswordLoginAuthenticationToken() {
        super(true);
    }
    public UsernamePasswordLoginAuthenticationToken(boolean authenticated) {
        super(authenticated);
    }

    public void setPrincipal(Object principal) {
        this.principal = principal;
    }

    public void setCredentials(Object credentials) {
        this.credentials = credentials;
    }

    @Override
    public Object getCredentials() {
        // 认证成功了，就不用在存储密码等重要信息到内存
        return credentials;
    }

    @Override
    public Object getPrincipal() {
        return principal;
    }

}
